package fhp.hlhj.giantfold.adapter

import android.content.Context
import android.util.SparseArray
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.BaseAdapter
import android.widget.TextView
import com.bumptech.glide.Glide
import fhp.hlhj.giantfold.R
import kotlinx.android.synthetic.main.tabbao_header_item.view.*

/**
 * author: FHP
 * data: on 2017\11\23 0023 15:29
 * E-Mail: 103945089@qq.com
 */
class TabBaoHeaderGridViewAdp(private var context: Context,private var datas:List<String>) :BaseAdapter() {

    override fun getView(p0: Int, p1: View?, p2: ViewGroup?): View {
        var p1 =p1
        if (p1==null){
            p1=LayoutInflater.from(context).inflate(R.layout.tabbao_header_item,null)
        }
        Glide.with(context).load(R.mipmap.exp2).asBitmap().into(p1?.itemIcon)
        val textView = p1?.findViewOften<TextView>(R.id.itemTitle)
        textView?.text = "动态名字"
        return p1!!
    }
    override fun getItem(p0: Int): Any {
        return datas[p0]
    }

    override fun getItemId(p0: Int): Long {
        return p0.toLong()
    }

    override fun getCount(): Int {
        return datas.size
    }

    fun <T : View> View.findViewOften(viewId: Int): T {
        var viewHolder: SparseArray<View> = tag as? SparseArray<View> ?: SparseArray()
        tag = viewHolder
        var childView: View? = viewHolder.get(viewId)
        if (null == childView) {
            childView = findViewById(viewId)
            viewHolder.put(viewId, childView)
        }
        return childView as T
    }
}